package com.ips.utils;


import com.ips.utils.exception.OperationException;
import com.ips.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 控制器增强 配合ExceptionHandler实现全局捕抓异常
 */
@ControllerAdvice
@Slf4j
public class ExceptionAdvice {

    @ExceptionHandler(value = OperationException.class)   // 捕获的异常类型，我们只需要把需要捕获异常类型写进来就好
    @ResponseBody
    public Result exceptionHandler(OperationException ex) {
        return Result.error(ex.getMessage(), ex.getCode());
    }

}
